﻿using Oxygen.Client.ServerProxyFactory.Interface;
using RpcInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClientSample
{
    public class ClientCallService : IClientCallService
    {
        private readonly IServiceProxyFactory _serviceProxyFactory;
        private readonly IStateManager _stateManager;
        public ClientCallService(IServiceProxyFactory serviceProxyFactory,
            IStateManager stateManager)
        {
            _serviceProxyFactory = serviceProxyFactory;
            _stateManager = stateManager;
        }

        public async Task<dynamic> Call()
        {
            var remoteService = _serviceProxyFactory.CreateProxy<IHelloService>();
            await _stateManager.SetState(new TestState() { Data = new OutDto() { Word = "1232" } });
            var result1 = await remoteService.HelloWorld();
            var result2 = await remoteService.HelloWorldByName(new InputDto() { Name = "huawei" });
            var result3 = await remoteService.HelloWorldByEvent();
            return new { result1, result2, result3 };
        }

        public async Task<dynamic> GetProduct()
        {
            var actorService = _serviceProxyFactory.CreateActorProxy<IProductService>();
            return await actorService.Get(new ProductInput() { ActorId = "1", ProductId = 1 });
        }

        public async Task<dynamic> ProductReduceStock()
        {
            var actorService = _serviceProxyFactory.CreateActorProxy<IProductService>();
            return await actorService.ReduceStock(new ProductInput() { ActorId = "1", ProductId = 1, ReduceStock = 1 });
        }
    }
}
